package com.example.servletdemo.servlet.listner.session;

import com.example.servletdemo.listner.session.MyHttpSessionBindingListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/SessionBindingAddServlet")
public class SessionBindingAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //HttpSession属性的设置
        HttpSession session = req.getSession();

        MyHttpSessionBindingListener myHttpSessionBindingListener = new MyHttpSessionBindingListener();

        session.setAttribute("abc",myHttpSessionBindingListener);
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("MyHttpSessionBindingListener abc 被添加了："+req.getAttribute("abc")+"\n");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
